<script>	
var oid={echo $oid};

function SubmitComment(oid){
	var obj=$('#Comment_Text_'+oid);
	var value=obj.val();
	
	if(value){
		 $.post('{echo U("/post/task/postcomment/id/".$id)}',{oid:oid,content:value,Submit:1}, function(json) {
					
				$('.bootbox').PhpappProgress({json:json});
	
				if(json.data.comment_num){
		
					$('#Comment_More_'+oid).show(300);
					$('#Comment_More_'+oid).find("span").html(parseInt(json.data.comment_num));
			
					var html='';
					for(var key in json.data.comment){
						
						html+='<div class="row"><div class="col-lg-1 comment_avatar">'+json.data.comment[key].avatar+'</div><div class="col-lg-10  comment"><div class="row"><span>'+json.data.comment[key].username+' 发表于 '+json.data.comment[key].adddate+'</span><br />'+json.data.comment[key].content+'</div></div></div>';
						//console.log(json.data.comment[key].username);
					}
					
					$('#CommentList_'+oid).html(html);
					
				}
				
				$('#Comment_Text_'+oid).val('');
				
				bootbox.hideAll();
				
				return true;
					
		 }, 'json');
		 
		  bootbox.dialog({
				 message: '<div class="progress progress-striped active"><div style="width: 1%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="20" role="progressbar" class="progress-bar progress-bar-info"><span>0%</span></div></div>',
				 title: '<i class="icon fa fa-retweet"></i> 提交中',
				 closeButton: false
		 }).PhpappProgress({time:3000});
	 
		  return false; 
		
	}else{
		
		 bootbox.dialog({
			 message: '请输入评论内容！',
			 title: '<i class="icon fa fa-warning"></i> 提示',
			  buttons: {
                    "确定": {
                        className: "btn-default"
                    }
                }
		 })
	}
	
}

function GetListComment(url){
	if(oid){
		$('#CommentList_'+oid).html('加载中...');
		$.getJSON(url, function(json){
			if(json.status=='ok'){
				if(json.data.list){
					$.each(json.data.list, function(i,item){
						var comment='';
						if(item.comment){
							for(var key in item.comment){
								comment+='<div class="row"><div class="col-lg-1 comment_avatar">'+item.comment[key].avatar+'</div><div class="col-lg-10  comment"><div class="row"><span>'+item.comment[key].username+' 发表于 '+item.comment[key].adddate+'</span><br />'+item.comment[key].content+'</div></div></div>';
							}
						}
						
						$('#CommentList_'+oid).html(comment);
						
						var pagecomment='';
						if(item.pagecomment){
							pagecomment='<ul class="pagination">'+item.pagecomment+'</ul>';
						}
						
						$("#PageComment").html(pagecomment);
						
					});
					
				}
			}
		});
	}
}


function GetListDraft(url,listdiv){
	$(listdiv).html('加载中...');
	$.getJSON(url, function(json){
		if(json.status=='ok'){
			if(json.data.list){
				if(json.data.page){
					$("#ShowPage").html('<ul class="pagination">'+json.data.page+'</ul>');
				}
				$(listdiv).html('');
				$.each(json.data.list, function(i,item){
					//alert(item.oid);
					var draft_success='';
					if(item.process==1){
						draft_success='<div class="draft_success"></div>';
					}else if(item.process==2){
						draft_success='<div class="draft_failure"></div>';
					}
					
					var proposal='';
					if(item.proposal){
						 proposal='<div class="draft_warning" style="margin-bottom:10px;">雇主审语：'+item.proposal+'</div>';
					}
					
					var comment='';
					if(item.comment){
						for(var key in item.comment){
							comment+='<div class="row"><div class="col-lg-1 comment_avatar">'+item.comment[key].avatar+'</div><div class="col-lg-10  comment"><div class="row"><span>'+item.comment[key].username+' 发表于 '+item.comment[key].adddate+'</span><br />'+item.comment[key].content+'</div></div></div>';
						}
					}
					
					var buyer_read='雇主未浏览';
					if(parseInt(item.buyer_read)==1){
						buyer_read='雇主已浏览';
					}
					
					var buyer_process='未审核';
					if(parseInt(item.process)){
						buyer_process='已审核';
					}
					
					var verify_time='';
					if(item.verifytime){
						verify_time=' 审核时间：'+item.verifytime;
					}
					
					var offer='';
					if(parseInt(item.offer)>0 && parseInt(item.time)>0){
						var offer='<div class="row"><div class="col-lg-8"><hr/><h5>'+'报价：<strong class="text-primary">'+item.offer+'</strong> 元 &nbsp; 时间：<strong class="text-primary">'+item.time+'</strong> 天 &nbsp; 地区：<span class="text-primary">南宁</span></h5><hr/></div></div>';
					}
					
					$(listdiv).append('<div class="row">'+
							 '<div class="col-lg-1">'+item.avatar+
					
							 '</div>'+
							  
							 '<div class="col-lg-11">'+
							  
								   '<div class="row">'+
								   
								   '<div class="col-lg-9 color_999">'+
										'<b>'+item.seller_username+'</b> <i class="fa fa-clock-o"></i> '+item.dateline+' &nbsp; '+buyer_read+'  ,'+buyer_process+ verify_time+
								  ' </div>'+
									'<div class="col-lg-3">'+draft_success+'<div class="text-right">#'+item.oid+'  <input name="" type="checkbox" value="" /></div>'+
								 ' </div>'+
								  ' </div>'+offer+proposal+item.content+
								   '<div class="row">'+
								  ' <div class="col-lg-12 col-pt-20">'+
								   '<div id="CommentList_'+item.oid+'">'+comment+
								   '</div><div class="row"><div class="col-lg-11"><div class="dataTables_paginate paging_bootstrap text-right col-pt-20" id="PageComment"><ul class="pagination">'+item.pagecomment+'</ul></div></div></div>'+
								   
								  '<p class="col-pt-10"><a class="btn btn-default btn-sm" href="javascript:void(0);" onclick="OpenComment('+item.oid+','+item.seller_uid+')"><i class="fa fa-comment-o"></i>评论</a> '+ 
								  
								  
								  '<a class="btn btn-default btn-sm" target="_blank" href="{echo U('/task/'.$id)}/'+item.oid+'" id="Comment_More_'+item.oid+'"><i class="fa fa-comments-o"></i>更多评论(<span>'+item.comment_num+'</span>)</a> '+
							
								  '<a class="btn btn-default btn-sm" href="javascript:void(0);" onclick="PostReport({echo $id},'+item.oid+',3);"><i class="fa fa-bookmark-o"></i>举报</a></p>'+
								  
								  '<div id="Comment_'+item.oid+'" style="display:none">'+
									'<span class="input-icon icon-right">'+
										  ' <textarea placeholder="您想说点什么?" class="form-control" rows="2" id="Comment_Text_'+item.oid+'" name="content"></textarea>'+
										   '<i class="fa fa-comment-o themeprimary"></i>'+
									  ' </span>'+
								  
									'<p class="col-pt-10 text-right">'+
									   '<button class="btn btn-default btn-sm" type="button" onclick="CancelComment('+item.oid+')">取 消</button> <button class="btn btn-darkorange btn-sm" type="submit" onclick="SubmitComment('+item.oid+')">评 论</button>'+
									 '</p>'+
									 
									'</div>'+item.operate+
									 
								   
		 
									' </div>'+
					
									 '</div>'+
							  
							  '</div>'+
					'</div>');


				});
			}
		}else{  
			$(listdiv).html(json.message);
		}
	});
}



/* 中标 */
function ApplySuccess(oid,type,pagenum){
	 bootbox.confirm({  
		   buttons: {  
			  confirm: {  
				 label: '确认',  
			  },  
			  cancel: {  
				 label: '取消',  
			  }  
		   },  
		   title:'提示',
		   message: '<i class="glyphicon glyphicon-warning-sign"></i> 您确认要操作'+oid+'号稿件中标?',  
			   callback: function(result) {  
				  if(result) {  
					 bootbox.hideAll();
					 
					 $.post('{echo U("/post/task/success/id/".$id)}',{oid:oid,type:type,pagenum:pagenum}, function(json) {
								
							$('.bootbox').PhpappProgress({json:json});

							return true;
								
					 }, 'json');
					 
					  bootbox.dialog({
							 message: '<div class="progress progress-striped active"><div style="width: 1%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="20" role="progressbar" class="progress-bar progress-bar-info"><span>0%</span></div></div>',
							 title: '<i class="icon fa fa-retweet"></i> 提交中',
							 closeButton: false
					 }).PhpappProgress({time:2000});
				 
					  return false; 
		  
		  
				  }
			   } 
	
	   })
	   
	   return false;
}

/* 失败 */
function ApplyFailure(oid,type,pagenum){
	bootbox.confirm({  
		   buttons: {  
			  confirm: {  
				 label: '确认',  
			  },  
			  cancel: {  
				 label: '取消',  
			  }  
		   },  
		   title:'提示',
		   message: '<i class="glyphicon glyphicon-warning-sign"></i> 您确认要操作'+oid+'号稿件不合格?',  
			   callback: function(result) {  
				  if(result) {  
					 bootbox.hideAll();
					 
					 $.post('{echo U("/post/task/failure/id/".$id)}',{oid:oid,type:type,pagenum:pagenum}, function(json) {
								
							$('.bootbox').PhpappProgress({json:json});

							return true;
								
					 }, 'json');
					 
					  bootbox.dialog({
							 message: '<div class="progress progress-striped active"><div style="width: 1%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="20" role="progressbar" class="progress-bar progress-bar-info"><span>0%</span></div></div>',
							 title: '<i class="icon fa fa-retweet"></i> 提交中',
							 closeButton: false
					 }).PhpappProgress({time:2000});
				 
					  return false; 
		  
		  
				  }
			   } 
	
	   })
	   
	   return false;
}


						
$(function(){
	GetListDraft("{echo U('/post/task/listdraft/id/'.$id.'/type/0/oid/'.$oid)}",'#ListDraft');
});
</script>